import jwt from 'jsonwebtoken';
import { env } from '../config/env';

const JWT_SECRET = env.jwtSecret;

export const signToken = (payload: object) => {
  const safePayload = JSON.parse(JSON.stringify(payload, (_, v) =>
    typeof v === 'bigint' ? v.toString() : v
  ));
  return jwt.sign(safePayload, JWT_SECRET, { expiresIn: '7d' });
};
export const verifyToken = (token: string) => {
  return jwt.verify(token, JWT_SECRET) as { id: number; username: string };
};
